import csv

from board import Board

def getAllLevels():
    levels = []
    with open('levels.tsv', 'rb') as tsvin:
        reader = csv.reader(tsvin, delimiter='\t')
        level_rows = []
        for i, row in enumerate(reader):
            level_rows.append(row)
            
            if i % 10 == 9:  # Finished reading level. (Each level is represented by 10 lines.)
                levels.append(Board(level_rows))
                level_rows = []  # Reset the array for the next level.
    return levels

def getLevel(l):
    with open('levels.tsv', 'rb') as tsvin:
        reader = csv.reader(tsvin,delimiter='\t')
        level_rows = []
        for i, row in enumerate(reader):
            level_rows.append(row)
            
            if i % 10 == 9:  # Finished reading level. (Each level is represented by 10 lines.)
                if level_rows[0][0] == l:
                    return Board(level_rows)
                
                level_rows = []  # Reset the array for the next level.
        return None

def printLevels():
    for level in getAllLevels():
        print level

#printLevels()